﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StrategyGame
{
    public class Arena
    {
        public List<List<ArenaSquare>> Squares;

        public void SlideSide(int pivotPoint, int direction, int player)
        {
            var backRow = player == 1 ? 0 : 3;

            for (int n = pivotPoint; n > 0 && n < Squares[player].Count; n += direction)
            {
                var currentSquare = Squares[player][n];
                var nextSquare = Squares[player][n + direction];
                if (nextSquare.Character == null)
                    break;
                currentSquare.Character = nextSquare.Character;

                currentSquare = Squares[backRow][n];
                nextSquare = Squares[backRow][n + direction];
                currentSquare.Character = nextSquare.Character;

            }
        }
        public List<ArenaSquare> GetTargetedSpaces(ArenaSquare origin, List<SimplePoint> spaces)
        {
            var targetSquares = new List<ArenaSquare>();
            var direction = origin.Row == 1? 1: -1;
            foreach (var space in spaces)
            {
                int row, col;
                row = origin.Row + (direction * space.RowOffset);
                col = origin.Column + (direction * space.ColOffset);
                if (row < 0 || col < 0 || row >= Squares.Count || col >= Squares[row].Count)
                    continue;
                targetSquares.Add(Squares[row][col]);
            }

            return targetSquares;
        }

        public Arena()
        {
            Squares = new List<List<ArenaSquare>>();
            for (int n = 0; n < 4; n++)
            {
                var newRow = new List<ArenaSquare>();

                for (int m = 0; m < 5; m++)
                {
                    newRow.Add(new ArenaSquare());
                }
                Squares.Add(newRow);
            }

        }

       

    }
}
